﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using System.Data.OleDb;
using System.Data.Odbc;
using System.Data.SqlClient;

namespace myStackSandbox
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            FormsAuthentication.RedirectFromLoginPage(Login1.UserName, false);
            return;

            /////////////////////
            string user = Login1.UserName;
            string pw = Login1.Password;

            SqlConnection conn = new SqlConnection("Data Source=myStack2.db.4256415.hostedresource.com;Initial Catalog=myStack2;Persist Security Info=True;User ID=myStack2;Password=P@dres!210");
            conn.Open();

            string user_query = String.Format("Select user_name from user where user_name='{0}' and user_password='{1}'", user, pw);
            SqlCommand command = new SqlCommand(user_query, conn);
            SqlDataReader reader = command.ExecuteReader();

            if (reader.Read())
            {
                FormsAuthentication.RedirectFromLoginPage(user, false);
            }
            else
            {

            }


            conn.Close();
        }

        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            string user = CreateUserWizard1.UserName;
            string pw = CreateUserWizard1.Password;
            string email = CreateUserWizard1.Email;

            SqlConnection conn = new SqlConnection("Data Source=myStack2.db.4256415.hostedresource.com;Initial Catalog=myStack2;Persist Security Info=True;User ID=myStack2;Password=P@dres!210");
            conn.Open();

            string insert = String.Format("INSERT INTO user (user_name, user_email, user_password) VALUES ({0}, {1}, {2})", user, email, pw);
            SqlCommand command = new SqlCommand(insert, conn);
            command.ExecuteNonQuery();

            conn.Close();

            FormsAuthentication.RedirectFromLoginPage(user, false);
        }
    }
}
